package com.study.order.controller;

import com.study.order.bean.Order;
import com.study.order.confg.OrderConfig;
import com.study.order.service.IOrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * @Author: WPX
 * @Create: 2025/07/31
 **/
//@RefreshScope
@RestController
public class OrderController {
    @Autowired
    private IOrderService orderService;
    @Autowired
    private OrderConfig orderConfig;

//    @Value("order.timeout")
//    private String timeout;
//    @Value("order.auto-confirm")
//    private String autoConfirm;
//    @Value("order.db-url")
//    private String dbUrl;

    @GetMapping("/create")
    public Order createOrder(@RequestParam("userId") Long userId,
                             @RequestParam("productId") Long productId) {
        return orderService.createOrder(userId, productId);
    }

    @GetMapping("/config")
    public String config() {
        return "timeout=" + orderConfig.getTimeout() + ";autoConfirm=" + orderConfig.getAutoConfirm() + ";dbUrl=" + orderConfig.getDbUrl();
    }
}
